<html>
<head>
<title>Fact Vote Test</title>
<link rel="stylesheet" type="text/css" href="wick.css" />
<script type="text/javascript" language="JavaScript" src="jquery.js"></script>
<script type="text/javascript" language="JavaScript" src="jquery.livequery.js"></script>
<script>
$(document).ready(function(){

  $.ajax({
    type: "GET",
    url: "http://localhost:8080/all/user",
    dataType: "json",
    success: onLoadAllUser
  });
  
  //getting facts
  $.ajax({
    type: "POST",
    url: "http://localhost:8080/fact/get",
    dataType: "json",
    data: ({user_id : 'user1', fact_query : 'latest',fact_page:1}),
    success: onFactGet
  });
  
  // setting vote
  $("form#fact-vote-form").submit(function(){
  $.ajax({
    type: "POST",
    url: "http://localhost:8080/fact/vote",
    dataType: "text",
    data: ({user_id : $("#userid").val(), fact_key : $("#fact-key").val(), vote: $("#vote").val()}),
    success: onVoteGet
  });
  return false;
  });

});

function onLoadAllCountry(data, textStatus) {
  window.all_country_full = data;
  window.all_country_coll = [];
  $.each(data, function(i,val){all_country_coll[i]=val.country_name;});
}

function onLoadAllUser(data, textStatus) {
  window.all_user_full = data;
  window.all_user_coll = [];
  $.each(data, function(i,val){
    all_user_coll[i]=val.userid;
    $("#userid").append("<option value=\""+val.userid+"\">"+val.userid+"</option>");
  });
}

function onLoadAllClub(data, textStatus) {
  window.all_club_full = data;
  window.all_club_coll = [];
  $.each(data, function(i,val){all_club_coll[i]=val.name;$("#fact-tag").append("<option value=\""+val.key+"\">"+val.name+"</option>");});
}

function onLoadAllPlayer(data, textStatus) {
  window.all_player_full = data;
  window.all_player_coll = [];
  $.each(data, function(i,val){all_player_coll[i]=val.name;$("#fact-tags").append("<option value=\""+val.key+"\">"+val.name+"</option>");});
}

function onFactGet(data, textStatus) {
  //TODO make better
  $.each(data, function(i,val){$("#fact-key").append("<option value=\""+val.key+"\">"+val.content+"</option>");});
}

function onVoteGet(data, textStatus) {
  //TODO make better
$("#fact-container").append(data);
}


</script>
</head>
<body>
<form id="fact-vote-form" action="http://localhost:8080/fact/getty" method="POST">
<div> 
Get Facts: 
User id=<select id="userid" name="user-id"/></select>
Fact key=<select id="fact-key" name="fact-key"/></select>
Vote=<select id="vote" name="vote" multiple="multiple"/><option value="up">UP</option><option value="down">DOWN</option></select>
<input id="fact-vote-submit" name="fact-vote-submit" type="submit" value="Go">
</div>
</from>
<div id="fact-container" style="margin:40px 20px;border:2px solid #ddd;padding:10px"></div>
<script type="text/javascript" language="JavaScript" src="wick.js"></script>
</body>
</html>

